<?php
/**
 * 地区模型
 * User: wuhao
 * Date: 2017/5/5
 * Time: 15:49
 */
namespace app\backend\model;

use think\Model;

class Area extends Model
{
    private $areaTable = 'z_area';
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取省份
     * @date   2016-1-9
     * @author Lanlc
     *
     *
     * @return
     */
    public function getArea($id)
    {
        if (!$id) {
            return false;
        }
        if (is_array($id)) {//省份信息
            $where = [
                'area_id' => ['IN', $id]
            ];
        } else {//某个省的城市信息或某市的区县信息
            $where = [
                'area_parent_id' => $id
            ];
        }

        $res = $this->table($this->areaTable)->where($where)->field('area_id as code, area_name as name, area_parent_id')->select();
        return $res;
    }
}